package migrations

import (
	"database/sql"
	"time"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/migrate"

	"gorm.io/gorm"
)

func init() {

	// 司机信息表
	type Driver struct {
		models.BaseModel

		UserId                uint64    `gorm:"column:user_id;comment:用户id;index;" db:"user_id" json:"user_id" form:"user_id"`
		Year                  uint      `gorm:"column:year;comment:驾龄;" db:"year" json:"year" form:"year"` // 驾龄
		Balance               int64     `gorm:"column:balance;comment:账号余额，可为负数;" db:"balance" json:"balance" form:"balance"`
		LicenseNumber         string    `gorm:"type:varchar(255);comment:驾驶证号码;index;" db:"license_number" json:"license_number" form:"license_number"`                           //驾驶证号码
		DriverNumber          string    `gorm:"type:varchar(255);comment:行驶证号码;index;" db:"driver_number" json:"driver_number" form:"driver_number"`                              //驾驶证号码
		LicenseType           string    `gorm:"type:varchar(255);comment:驾驶证类型;index;" db:"license_type" json:"license_type" form:"license_type"`                                 //驾驶证类型
		IdCard                string    `gorm:"type:varchar(20);comment:身份证号码;index;" db:"id_card" json:"id_card" form:"id_card"`                                                 //驾驶证类型
		LicenseExpirationDate time.Time `gorm:"type:timestamp;comment:驾驶证过期日期;index;" db:"license_expiration_date" json:"license_expiration_date" form:"license_expiration_date"` //驾驶证过期日期
		EmergencyContactName  string    `gorm:"type:varchar(255);comment:紧急联系人姓名;" db:"emergency_contact_name" json:"emergency_contact_name" form:"emergency_contact_name"`       //紧急联系人姓名
		EmergencyContactPhone string    `gorm:"type:varchar(255);comment:紧急联系人电话;" db:"emergency_contact_phone" json:"emergency_contact_phone" form:"emergency_contact_phone"`    //紧急联系人电话
		TripsCount            int64     `gorm:"comment:发布的行程总数;" db:"trips_count" json:"trips_count" form:"trips_count"`
		models.CommonTimestampsField
	}

	up := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.AutoMigrate(&Driver{})
	}

	down := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.DropTable(&Driver{})
	}

	migrate.Add("2023_07_18_105620_add_drivers_table", up, down)
}
